﻿using Mrc.Common.Enum;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace Mrc.Common.SystemInfo
{
    public class PlatformTypeInfo
    {
        /// <summary>
        /// 系统版本枚举
        /// </summary>
        private static SystemTypeEnum _platform = SystemTypeEnum.None;
        /// <summary>
        /// 是否是windows环境
        /// </summary>
        public static bool IsWindows=>GetPlatform()==SystemTypeEnum.Windows;
        /// <summary>
        /// 是否是Linux环境
        /// </summary>
        public static bool IsLinux => GetPlatform() == SystemTypeEnum.Linux;
        /// <summary>
        /// 是否是OSX环境
        /// </summary>
        public static bool IsOSX => GetPlatform()==SystemTypeEnum.OSX;

        private static SystemTypeEnum GetPlatform()
        {
            if(_platform != SystemTypeEnum.None) return _platform;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) _platform = SystemTypeEnum.Windows;

            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) _platform = SystemTypeEnum.Linux;

            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) _platform = SystemTypeEnum.OSX;
            
            else { }
            
            return _platform;
        }
    }
}
